//
//  XZHSearchBar.m
//  Piece
//
//  Created by Zeaho on 16/6/10.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "XZHSearchBar.h"
#import "JXLDayAndNightMode.h"

@implementation XZHSearchBar
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tintColor = [UIColor clearColor];
    }
    return self;
}

-(void) layoutSubviews
{
    [super layoutSubviews];
    
    UITextField *searchField = nil;
    NSArray *subviewArr = self.subviews;
    for(int i = 0; i < subviewArr.count ; i++) {
        UIView *viewSub = [subviewArr objectAtIndex:i];
        NSArray *arrSub = viewSub.subviews;
        for (int j = 0; j < arrSub.count ; j ++) {
            id tempId = [arrSub objectAtIndex:j];
            if([tempId isKindOfClass:[UITextField class]]) {
                searchField = (UITextField *)tempId;
            }
        }
    }
    //自定义UISearchBar
    if(searchField) {
        searchField.textAlignment = NSTextAlignmentLeft;
//        searchField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 5, 20)];
        searchField.tintColor = [UIColor colorWithRed:0.60 green:0.60 blue:0.60 alpha:1.00];
        searchField.layer.cornerRadius = 15;
        //        searchField.width =  MAIN_SCREEN_WIDTH - 60;
        
        [searchField setBorderStyle:UITextBorderStyleRoundedRect];
        [searchField setBackgroundColor:[UIColor colorWithRed:0.86 green:0.87 blue:0.90 alpha:1.00]];
        [searchField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
        [searchField setTextColor:[UIColor colorWithRed:0.60 green:0.60 blue:0.60 alpha:1.00]];
        searchField.center = self.center;
    }
    //外部背景
    UIView *outView = [[UIView alloc] initWithFrame:self.bounds];
    [outView setBackgroundColor:[UIColor colorWithRed:0.86 green:0.87 blue:0.90 alpha:1.00]];
    [self insertSubview:outView atIndex:1];
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
